﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
 * 创建时间：2014/12/27 19:44:43
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace ComicIsland.Common.Serializer
{
    public class ByteSerializer : ISerializer
    {
        public ByteSerializer()
        {
        }

        public object Deserialize(Stream streamObject)
        {
            if (streamObject == null)
            {
                return null;
            }
            byte[] numArray = new byte[streamObject.Length];
            streamObject.Read(numArray, 0, (int)streamObject.Length);
            return numArray;
        }

        public void Serialize(Stream streamObject, object obj)
        {
            if (obj == null || streamObject == null)
            {
                return;
            }
            if (typeof(byte[]) == obj.GetType())
            {
                byte[] numArray = (byte[])obj;
                streamObject.Write(numArray, 0, (int)numArray.Length);
            }
        }
    }
}
